﻿Public Class Frm7SalidaAgregar
    Public Function cargarsocio() As Boolean
        'Objeto Roles
        Dim accion As New SocioDAO
        Dim dato As New Socio
        dato.pIdtsocio = 1
        'Tabla temporal de roles
        Dim tabla As DataTable
        tabla = accion.mostrar_entradas(dato)
        'Comprobar si hay roles
        If tabla Is Nothing Then
            Return False
        Else

            'Trabajar con el control combox
            With ComboBox2
                'No se permite modificar
                .DataSource = accion.mostrar_entradas(dato)
                'Fuentes de dtao
                .DropDownStyle = ComboBoxStyle.DropDownList
                'Campo a mostrar
                .DisplayMember = "Nombre"
                'Clave principal
                .ValueMember = "ID_Socio"
                'No mostrar ningun rol
                .SelectedIndex = -1
            End With
            Return True
        End If
    End Function
    Public Function cargarbodega() As Boolean
        'Objeto Roles
        Dim accion As New BodegaDAO
        'Tabla temporal de roles
        Dim tabla As DataTable
        tabla = accion.mostrar
        'Comprobar si hay roles
        If tabla Is Nothing Then
            Return False
        Else

            'Trabajar con el control combox
            With ComboBox1
                'No se permite modificar
                .DataSource = accion.mostrar
                'Fuentes de dtao
                .DropDownStyle = ComboBoxStyle.DropDownList
                'Campo a mostrar
                .DisplayMember = "Descripcion"
                'Clave principal
                .ValueMember = "ID_Bodega"
                'No mostrar ningun rol
                .SelectedIndex = -1
            End With
            Return True
        End If
    End Function
    Public Sub cargarRegistros()
        Try
            Dim accion As New MovimientosDAO
            'Llenar tabla
            'lblIDMovimiento.Text = accion.mostrarUltimoRegistro
            Dim tabla As New DataTable
            tabla = accion.mostrarUltimoRegistro
            Label13.Text = registroUltimo
            ''Comprobar si hay datos
            'If Not tabla Is Nothing Then
            '    'Cargar datos en el grid
            '    'dgv1.DataSource = tabla
            '    'FormatosGrid.funciones.formatoGrid_Usuarios(DGV1, tabla)
            '    'Mostrar datos en los controles
            '    lblIDMovimiento.Text = tabla.Rows(0).Item(0).Value
            '    'DGV1.Rows(fila).Selected = True
            '    'DGV1.CurrentCell = DGV1.Rows(fila).Cells(1)
            'End If
        Catch ex As Exception
            MessageBox.Show(ex.Message, "Advertencia", MessageBoxButtons.OK,
                        MessageBoxIcon.Warning)
        End Try
    End Sub
    Public Sub cargarInventario(ByVal fila As Integer)
        Try
            Dim dato As New Inventario
            Dim accion As New InventarioDAO
            dato.pIDmovimiento = Label13.Text

            'Llenar tabla
            Dim tabla As New DataTable
            tabla = accion.mostrar_salidas(dato)
            'Comprobar si hay datos
            'If Not tabla Is Nothing Then
            'Cargar datos en el grid
            'DGV2.DataSource = tabla
            FormatosGrid.formatoGrid_Mostrar_Movimiento(DAGV2, tabla)
            'Mostrar datos en los controles
            'lblIDSocio.Text = DGV1.Rows(fila).Cells(0).Value
            'txtCodigo.Text = DGV1.Rows(fila).Cells(1).Value
            'txtNombre.Text = DGV1.Rows(fila).Cells(2).Value
            'txtDireccion.Text = DGV1.Rows(fila).Cells(3).Value
            'txtDocumento.Text = DGV1.Rows(fila).Cells(4).Value
            'txtTelefono.Text = DGV1.Rows(fila).Cells(5).Value
            'txtEmail.Text = DGV1.Rows(fila).Cells(6).Value
            'txtContacto.Text = DGV1.Rows(fila).Cells(7).Value
            'lblTipo.Text = DGV1.Rows(fila).Cells(8).Value
            'lblIdTSocio.Text = DGV1.Rows(fila).Cells(9).Value
            ''Seleccionar toda la fila
            'DGV1.Rows(fila).Selected = True
            'DGV1.CurrentCell = DGV1.Rows(fila).Cells(1)
            'End If
        Catch ex As Exception
            MessageBox.Show(ex.Message, "Advertencia", MessageBoxButtons.OK,
                        MessageBoxIcon.Warning)
        End Try
    End Sub
    Private Sub Frm7SalidaAgregar_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'txtFiltro.Enabled = False
        'txtNombre.Enabled = False
        'txtCantidad.Enabled = False
        'btnAgregarLinea.Enabled = False
        'btnBorrar.Enabled = False
        cargarsocio()
        cargarbodega()
        TextBox5.Text = DateTime.Now.ToString("dd/MM/yyyy")
    End Sub

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        'Clase Usuario
        Dim dato As New Movimientos
        'Clase Operaciones
        Dim accion As New MovimientosDAO
        'Asignar los datos
        dato.pFehca = TextBox5.Text
        dato.pSocio = ComboBox2.SelectedValue
        dato.pBodega = ComboBox1.SelectedValue
        dato.pDescripcion = TextBox4.Text
        dato.pID_T_Documento = 2
        'Agregar registro
        If accion.agregar(dato) Then
            MessageBox.Show("Registro almacenado", "Guardar", MessageBoxButtons.OK, MessageBoxIcon.Information)
            cargarRegistros()

        Else
            MessageBox.Show("No se puede guardar el registro, contacte al administrador", "Advertencia", MessageBoxButtons.OK, MessageBoxIcon.Warning)
        End If


    End Sub


  
    Private Sub dagv1_CurrentCellChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DGV1.CurrentCellChanged
        Try
            If Not DAGV1.CurrentCell Is Nothing Then
                With DAGV1
                    Label9.Text = .Rows(.CurrentCell.RowIndex).Cells(0).Value
                    TextBox1.Text = .Rows(.CurrentCell.RowIndex).Cells(1).Value
                    LblInventario.Text = .Rows(.CurrentCell.RowIndex).Cells(2).Value
                End With
            End If
        Catch ex As Exception
            MessageBox.Show(ex.Message, "Advertencia", MessageBoxButtons.OK,
              MessageBoxIcon.Warning)
        End Try
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        Dim a, b As Integer
        a = TextBox3.Text
        b = LblInventario.Text
        If a > b Then
            MessageBox.Show("No hay sufiente inventario en la bodega para esta salida", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)

            TextBox3.Text = Nothing

            TextBox3.Focus()

        Else
            'Clase Roles
            Dim dato As New Inventario
            'Clase Operaciones
            Dim accion As New InventarioDAO
            'Asignar los datos

            dato.pIngresos = 0
            dato.pSalidas = TextBox3.Text
            dato.pIDproducto = Label9.Text
            dato.pIDmovimiento = Label13.Text
            'Agregar registro
            If accion.agregar(dato) Then
                MessageBox.Show("Registro almacenado", "Guardar", MessageBoxButtons.OK, MessageBoxIcon.Information)
                cargarInventario(0)
                TextBox3.Text = Nothing
            Else
                MessageBox.Show("No se puede guardar el registro, contacte al administrador", "Advertencia", MessageBoxButtons.OK, MessageBoxIcon.Warning)
            End If
        End If
        
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Frm7SalidasMenu.Show()
        Me.Close()
    End Sub

    Private Sub TextBox2_TextChanged_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox2.TextChanged
        Dim dato As New Items
        dato.pNC = TextBox2.Text
        Dim accion As New MovimientosDAO
        'Llenar tabla
        Dim tabla As New DataTable
        tabla = accion.mostrarFiltro_Salidas(dato)
        'Comprobar si hay datos
        If TextBox2.Text = Nothing Then
            DAGV1.DataSource = ""
            Label9.Text = Nothing
            TextBox1.Text = Nothing
            LblInventario.Text = Nothing
        Else

            If Not tabla Is Nothing Then
                'Cargar datos en el grid
                'DGV1.DataSource = tabla
                Label9.Text = tabla.Rows(0).Item(0)
                TextBox1.Text = tabla.Rows(0).Item(1)
                LblInventario.Text = tabla.Rows(0).Item(2)
                FormatosGrid.formatoGrid_Filtrar_Productos(DAGV1, tabla)
                'lblIDProducto.Text = DGV1.Rows(tabla).Cells(0).Value
                'txtNombre.Text = DGV1.Rows(fila).Cells(1).Value
                'txtTipo.Text = DGV1.Rows(fila).Cells(2).Value
                'lblIDTipo.Text = DGV1.Rows(fila).Cells(3).Value
                ''Seleccionar toda la fila
                'DGV1.Rows(fila).Selected = True
                'DGV1.CurrentCell = DGV1.Rows(fila).Cells(1)
            End If
        End If
    End Sub


End Class